package com.hall.controller;

import com.hall.pojo.CommentData;
import com.hall.pojo.CommentReplay;
import com.hall.service.CommentReplayService;
import com.hall.service.CommentReplayServiceImpl;
import com.hall.service.CommentServiceImpl;
import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping(value = "/commentReplay")
public class CommentReplayController {
    @Autowired
    private CommentReplayServiceImpl commentReplayService;
    @ModelAttribute
    public CommentReplay get(@RequestParam(required=false) String id) {
        CommentReplay entity = null;
        if (!StringUtils.isNullOrEmpty(id)){
            entity = commentReplayService.findCommentReplayById(id);
        }
        if (entity == null){
            entity = new CommentReplay();
        }
        return entity;
    }
    @RequestMapping(value = "list")
    public String Commenlist(CommentData commentData, Model model){
        return "commentlist";
    }
    @RequestMapping(value = "save")
    @ResponseBody
    public String saveComment(CommentReplay commentReplay, Model model){
        commentReplay.setCreateDate(new Date());
        commentReplayService.saveCommentReplay(commentReplay);
        return "ok";
    }
}
